package com.wenli.lt.controller;


import com.wenli.lt.service.IHomeService;
import com.wenli.lt.util.CommonResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lt
 * @since 2021-04-01
 */
@RestController
@RequestMapping("/home")
@Api(tags = "主页商品显示数据")
public class HomeController {

    @Autowired
    IHomeService iHomeService;

    @PostMapping("updateHome")
    @ApiOperation("编辑保存 后台管理主页商城显示数据")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "goodsId",value = "首页展示商品ID",required = true),
                    @ApiImplicitParam(name = "homeId",value = "首页展示图片ID",required = true),
            }
    )
    public CommonResponse  updateHome(String goodsId,String homeId){
        if (iHomeService.updateHome(goodsId,homeId)){
            return new CommonResponse("更改成功!");
        }else {
            return new CommonResponse("更改失败,请联系管理员");
        }
    }
    @GetMapping("selectHome")
    @ApiOperation("根据类型 显示主页商品信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "classification",value = "商品类型(0服装1美妆2家具3书籍4生活百货5游戏装备 6首页)"),
            }
    )

    public CommonResponse selectHome(Integer classification){
       Map map =  iHomeService.selectHome(classification);
       return new CommonResponse(map);
    }

    @GetMapping("selectHomePage")
    @ApiImplicitParams({

    })
    @ApiOperation("获取后台主页管理数据")
    public CommonResponse selectHomePage(){
        Map map =        iHomeService.selectHomePage();
        return new CommonResponse(map);

    }


}
